package com.qidian.mes.md.service.impl;

import com.alibaba.fastjson2.JSON;
import com.qidian.mes.md.mapper.SupporterMapper;
import com.qidian.mes.md.service.SupporterService;
import com.qidian.mes.pojo.MaterialSupporter;
import com.qidian.mes.pojo.MdSupport;
import com.qidian.mes.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 小可怎么都睡不够
 * @Description:
 * @Time: 2024-04-08 22:36
 **/
@Service
public class SupporterServiceImpl implements SupporterService {
    @Autowired
    private SupporterMapper supporterMapper;

    @Override
    public QdResult addSupporter(MdSupport supporter) {
        supporterMapper.addSupporter(supporter);
        return QdResult.success();
    }

    @Override
    public QdResult deleteSupporterById(Long id) {
        supporterMapper.deleteSupporterById(id);
        return QdResult.success();
    }

    @Override
    public QdResult updateSupporter(MdSupport supporter) {
        supporterMapper.updateSupporter(supporter);
        return QdResult.success();
    }

    @Override
    public QdResult findSupporterById(Long id) {
        return QdResult.success(supporterMapper.findSupporterById(id));
    }

    @Override
    public QdResult findAllSupporters() {
        return QdResult.success(supporterMapper.findAllSupporters());
    }

    @Override
    public QdResult getCount() {
        return QdResult.success(supporterMapper.getCount());
    }

    @Override
    public QdResult findSupportersByCriteria(String keyword, Integer level, Integer score, int page, int size) {
        return QdResult.success(supporterMapper.findSupportersByCriteria(keyword, level, score, (page - 1) * size, size));
    }

    @Override
    public QdResult findSupporterByMat(String name, Integer level, Integer page, Integer size, Integer matId) {
        MdSupport mdSupport = new MdSupport();
        mdSupport.setNameZh(name);
        mdSupport.setLevel(level);
        //打印出所有参数
        System.out.println("name = " + name);
        System.out.println("level = " + level);
        System.out.println("page = " + page);
        System.out.println("size = " + size);
        System.out.println("matId = " + matId);
        System.out.println("mdSupport = " + mdSupport);
        return QdResult.success(supporterMapper.findSupporterByMat(mdSupport, matId, (page - 1) * size, size));
    }

    @Override
    public QdResult insertMatSup(MaterialSupporter materialSupporter) {
        supporterMapper.insertMatSup(materialSupporter);
        return QdResult.success();
    }

    @Override
    public QdResult deleteByIdSupport(Integer idSupport,Integer idMat) {
        supporterMapper.deleteByIdSupport(idSupport,idMat);
        return QdResult.success();
    }

    @Override
    public QdResult updateSupportCount(String data) {
        MaterialSupporter materialSupporter = JSON.parseObject(data, MaterialSupporter.class);
        supporterMapper.updateSupportCount(materialSupporter.getIdSupport(),materialSupporter.getIdMat(),materialSupporter.getCount());
        return QdResult.success();
    }

}
